package mp

import (
	"context"
	"errors"

	"ruikc.com/server/api/internal/db"
	"ruikc.com/server/api/internal/svc"
	"ruikc.com/server/api/internal/types"
	"ruikc.com/server/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassifyDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewClassifyDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassifyDeleteLogic {
	return &ClassifyDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ClassifyDeleteLogic) ClassifyDelete(req *types.IdJson) (resp string, err error) {
	has := db.ExistData(&models.Classify{
		Pid: req.Id,
	})
	if has {
		return "", errors.New("分类下有子分类，不能删除")
	}
	data := &models.Classify{
		Id: req.Id,
	}
	db.DeleteData(data)

	return "操作成功", nil
}
